package com.fire.control.system.module.security.dao;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.fire.control.system.dto.UserResultDTO;
import com.fire.control.system.entity.Company;
import com.fire.control.system.entity.DeviceGroup;
import com.fire.control.system.entity.Role;
import com.fire.control.system.entity.User;
import com.fire.control.system.support.protocol.security.SecurityRequestProtocol;

public interface SecurityMapper {
	// 通过条件查询安全人员列表
	public List<UserResultDTO> getUserListByCodition(SecurityRequestProtocol requestProtocol);

	public List<DeviceGroup> getDeviceGroup(SecurityRequestProtocol requestProtocol);

	// 获得安全人员列表
	/*@Select("select * from t_users users where users.id in (select ur.user_id from t_user_role ur where ur.role_id=#{roleId})")
	public List<User> getSecurityList(@Param("roleId") String roleId);*/

	// 获得用户的角色
	@Select("select * from t_roles r where r.id in (select ur.role_id from t_user_role ur where ur.user_id=#{userId})")
	public List<Role> getRoleByUserId(@Param("userId") String userId);

	// 查询用户所属机构
	@Select("select * from t_company c where c.id in (select u.company_id from t_users u where u.id=#{userId})")
	public Company getCompanyByUserId(@Param("userId") String userId);

	// 查询用户所在设备组
	@Select("select * from t_device_group dg where dg.id in (select udg.group_id from t_user_device_group udg where udg.user_id=#{userId})")
	public List<DeviceGroup> getDeviceGroupByUserId(@Param("userId") String userId);

	// 查询用户所在设备组
	@Select("select * from t_device_group")
	public List<DeviceGroup> getAllDeviceGroup();
	
	//获得该人员的上级管理员
	public List<User> getParentUser(String userId);
	
	//获取用户密码
	@Select("select u.password from t_users u where u.id = #{userId}")
	public String getSecurityOrPassWord(String userId);
	
	@Insert("insert into t_user_device_group(user_id,group_id) values(#{userId},#{groupId})")
	public int addUserDeviceGroup(@Param("userId")String userId,@Param("groupId")String groupId);
	
}
